/*
 * Flora2.java
 *
 * Created on 19 gennaio 2008, 16.13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package it.cnr.icib.flora2engine;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import net.sourceforge.flora.javaAPI.src.FloraObject;
import net.sourceforge.flora.javaAPI.src.FloraSession;

/**
 *
 * @author Nino
 */
public class Flora2 {
    
    private FloraSession floraSession;

    /** Creates a new instance of Flora2 */
    public Flora2(String xsb_bin_directory, String flora_directory) {
       
    	System.setProperty("PROLOGDIR",xsb_bin_directory);
        System.setProperty("FLORADIR",flora_directory);
        System.setProperty("XSB_BIN_DIRECTORY",xsb_bin_directory);
        System.setProperty("java.library.path",xsb_bin_directory);
        System.setProperty("ENGINE","Subprocess");
        
        floraSession=new FloraSession();
    }

    public boolean setPath(String dir_path) {
        if (dir_path == null || dir_path.trim().length() == 0) {
            System.out.println("Invalid path ");
            return false;
        }
        String setpath = String.valueOf(String.valueOf((new StringBuffer("asserta(library_directory('")).append(dir_path).append("'))")));
        return getFloraSession().getEngine().command(setpath);
    }

    
    public boolean loadFile(String filename, String moduleName){
        return getFloraSession().loadFile(filename, moduleName);
    
    }
    
    public boolean addFile(String filename, String moduleName){
        return getFloraSession().addFile(filename, moduleName);
    
    }
    
    public boolean ExecuteCommand(String command){
        return getFloraSession().ExecuteCommand(command);
    
    }
    
    public Iterator<FloraObject> ExecuteQuery(String query){
        return getFloraSession().ExecuteQuery(query);
    
    }
    
    
    public Iterator<HashMap<String,FloraObject>> ExecuteQuery(String query,Vector<String> vars){
        return getFloraSession().ExecuteQuery(query,vars);
    
    }
    
    
    public void close(){
        getFloraSession().close();
    
    }
    
    
    public FloraSession getFloraSession() {
        return floraSession;
    }

    public void setFloraSession(FloraSession floraSession) {
        this.floraSession = floraSession;
    }
}
